<template>
	<view>
		<view class="full" @click="closeFull"></view>
		
		<view class="login-out">
			<view><b>问题筛选条件</b></view>
			<view class="work-date" @click="showDate(true)">{{ data_list.jcStartTime == '' ? '请选择检查开始日期' : data_list.jcStartTime }}<view class="fr"><image src="/static/img/date-icon.png" class="work-date-icon"></image></view></view>
			<view class="work-date" @click="showDate(false)">{{ data_list.jcEndTime == '' ? '请选择检查结束日期' : data_list.jcEndTime }}<view class="fr"><image src="/static/img/date-icon.png" class="work-date-icon"></image></view></view>
			
			<u-cell-group>
				<u-cell-item title="检查部门" :value="orgname" :arrow="false"></u-cell-item>
				<u-cell-item title="检  查 人" :value="username" :arrow="false"></u-cell-item>
				<u-cell-item title="责任部门" :value="org == '' ? '请选择责任部门' : org" @click="show_picker = true;columns = org_options"></u-cell-item>
				<u-cell-item title="责  任 人" :value="person == '' ? '请选择责任人' : person" @click="show_picker=true;columns=person_options"></u-cell-item>
				<u-cell-item v-show="type == 4" title="是否销号" :value="status == '' ? '请选择' : status" @click="show_picker = true;columns = status_options"></u-cell-item>
			</u-cell-group>
			<view class="clearfix"></view>
			
			<view class="btn"><button class="cancel-btn" @click="reset"><b>重置</b></button><button class="default-btn fr" @click="ok"><b>确定</b></button></view>
		</view>
		
		<view class="full full2" v-show="show_date || show_picker"></view>
		<u-picker v-model="show_date" mode="time" @confirm="setDate" @cancel="cancel"></u-picker>
		<u-select v-model="show_picker" :list="columns" label-name="text" @confirm="onConfirm" @cancel="cancel"></u-select>
		
		<!-- <DatetimePicker v-show="show_date" type="date" v-model="currentDate" @confirm="setDate" @cancel="cancel"></DatetimePicker>
		<Picker v-show="show_picker" show-toolbar :columns="columns" @confirm="onConfirm" @cancel="onCancel"></Picker> -->
	</view>
</template>

<script>
export default{
	props : ['type'],
	data() {
		return {
			username : uni.getStorageSync('username') || '',
			orgname : '',
			org_options:'',
			person_options:'',
			status_options:[{text:'已销号',value:'3',extra:'status'},{text:'未销号',value:'4',extra:'status'}],
			currentDate : new Date(),
			columns: [],
			data_list : {
				"flowState": '',  // 流转状态 0 已保存  ,1 待处理,2 待验证,3销号 4未销号
				"jcEndTime": "", //检查结束时间
				"jcOrg": uni.getStorageSync('departid') || '',  //检查部门名称
				"jcPerson": this.getUserId(), //检查人名称 
				"jcStartTime": "",  //检查开始时间
				"zrOrg": "", //责任部门名称
				"zrPerson": ""//责任人名称
			},
			status : '',
			org : '',
			person : '',
			show_picker : false,
			show_date : false
		}
	},
	created() {
		this.initSearch();
	},
	methods:{
		closeFull() {
			this.$emit('closeFull');
		},
		showDate(bol) {
			this.type = bol;
			this.show_date = true;
		},
		reset() {
			this.currentDate = new Date();
			this.data_list = {
				"flowState": '',  // 流转状态 0 已保存  ,1 待处理,2 待验证,3销号 4未销号
				"jcEndTime": "", //检查结束时间
				"jcOrg": uni.getStorageSync('departid') || '',  //检查部门名称
				"jcPerson": this.getUserId() || '', //检查人名称 
				"jcStartTime": "",  //检查开始时间
				"zrOrg": "", //责任部门名称
				"zrPerson": ""//责任人名称
			};
			this.status = '';
		},
		cancel() {
			this.show_date = false;
			this.show_picker = false;
		},
		ok() {
			this.$emit('closeFull',this.data_list);
		},
		setDate(obj) {
			let str = obj.year+'/'+obj.month+'/'+obj.day;
			this.type ? this.data_list.jcStartTime = str : this.data_list.jcEndTime = str;
			this.cancel();
		},
		onConfirm(value, index) {
			if(value[0].extra.type == 'org') {
				this.org = value[0].label;
				this.data_list.zrOrg = value[0].extra.id;
				this.getPerson(value[0].extra.id);
			}else if(value[0].extra.type == 'person'){
				this.person = value[0].label
				this.data_list.zrPerson = value[0].extra.id;
			}else if(value[0].extra == 'status'){
				this.data_list.flowState = value[0].extra.id;
				this.status = value[0].label;
			}
			this.cancel();
		},
		initSearch() {
			this.fetch('GET',this.baseUrl()+'/home/getOrgTreeByPerson',{personId:this.getUserId()}).then((res)=>{
				if(res.returnCode == 1) {
					this.org_options = res.data;
					this.org_options.map((item)=>{
						item.children = '';
						item.extra = {type:'org',id:item.id};
						if(item.id == uni.getStorageSync('departid')) this.orgname = item.text;
					})
				}
			})
		},
		getPerson(id) {
			this.fetch('GET',this.baseUrl()+'/home/getUserListByOrgId',{departid:id}).then((res)=>{
				if(res.returnCode == 1) {
					this.person_options = res.data;
					this.person_options.map((item)=>{
						item.extra = {type:'person',id:item.id};
						item.text = item.username;
					})
				}
			})
		}
	}
}
</script>

<style scoped>
	.login-out{
		padding: 26px 0 0 26px;
	}
	.login-out>view:nth-child(1){
		margin-bottom: 16px;
	}
	.login-out>view:nth-child(2){
		font-size: 14px;margin-bottom: 12px;
	}
	.work-date{
		line-height: 50px;border-bottom: 1px solid #d7d7d7;color: #3E3A39;font-size: 14px;padding-right: 27px;
	}
	.work-date-icon{
		width: 15px;height: 15px;vertical-align: middle;
	}
	.btn{
		position: absolute;width: 100%;bottom: 5%;left: 0;padding: 0 15px;
	}
	.default-btn,.cancel-btn{
		width: 47%;display: inline-block;
	}
	.full2{
		z-index: 99;
	}
	.login-out>.status{
		line-height: 26px;border: 1px solid rgba(62, 58, 57, 0.4);padding: 0 13px;box-sizing: border-box;border-radius: 6px;margin-bottom: 16px;margin-right: 10px;font-size: 12px;position: relative;color: rgba(62, 58, 57, 0.7);
	}
	.login-out>.on{
		border: 1px solid #307BE0;color: #307BE0;
	}
	.login-out>.on::after{
		content: '';position: absolute;bottom: 0;right: -2px;background: url('/static/img/alarm-lv.jpg') no-repeat;background-size: 100% 100%;width: 15px;height: 15px;
	}
	.van-cell{
		padding: 15px 16px;
	}
	.van-cell__value{
		color: #000000;
	}
</style>
